const _ = require('lodash');
const ps = require('current-processes');
 
function render(){


ps.get(function(err, processes) {
 
    var sorted = _.sortBy(processes, 'cpu');
    var top5  = sorted.reverse().splice(0, 5);
 
    let cpuList=top5.map(item=>item.cpu);
    var blessed = require('blessed')
     , contrib = require('blessed-contrib')
     , screen = blessed.screen()
     , line = contrib.line(
         { style:
           { line: "yellow"
           , text: "green"
           , baseline: "black"}
         , xLabelPadding: 3
         , xPadding: 5
         , label: 'Title'})
     , data = {
         x: ['t1', 't2', 't3', 't4'],
         y:cpuList
      }
   screen.append(line) //must append before setting data
   line.setData([data])
 
   screen.key(['escape', 'q', 'C-c'], function(ch, key) {
     return process.exit(0);
   });
 
   screen.render()
});
}

setInterval(render,1000)
